package imper.graphic;


import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import TWLSlick.BasicTWLGameState;

public abstract class AppliState extends BasicTWLGameState
{
	protected DrawableManager _DrawableManager;
	protected ButtonManager _ButtonManager;
	protected Image _Cursor;
	protected int _MouseX;
	protected int _MouseY;
	protected int _StateID = -1;

	public AppliState( int pStateID )
	{
		_DrawableManager = new DrawableManager();
		_ButtonManager = new ButtonManager();
		this._StateID = pStateID;
	}

	public int getID()
	{
		return _StateID;
	}

	public void addElement(Clickable pClickable)
	{
		_ButtonManager.addClickable(pClickable);
	}

	public void addElement(DrawableClickable pDrawableClickable)
	{
		_ButtonManager.addClickable(pDrawableClickable);
		_DrawableManager.addDrawable(pDrawableClickable);
	}
	
	public void addElement(Drawable pDrawable)
	{
		_DrawableManager.addDrawable(pDrawable);
	}

	public void draw(GameContainer pGameContainer, Graphics pGraphics) throws SlickException
	{
		_DrawableManager.draw(pGameContainer, pGraphics);
		if (_Cursor != null)
		{
			_Cursor.draw(_MouseX, _MouseY);
		}
	}

	public void mouseClicked(int button, int x, int y, int clickCount)
	{
		_ButtonManager.click(x, y);
		// System.out.println("CLIC :"+x+","+y+" "+clickCount);
	}

	public void mouseMoved(int oldx, int oldy, int pNewX, int pNewY)
	{
		_MouseX = pNewX;
		_MouseY = pNewY;
	}

	public int getMouseX()
	{
		return _MouseX;
	}

	public int getMouseY()
	{
		return _MouseY;
	}

	public void setCursor(Image pCursor)
	{
		this._Cursor = pCursor;
	}
}
